package core.schedule.snake;

import org.apache.commons.dbcp.BasicDataSource;

import core.schedule.snake.data.mydao.BaseDAO;
import core.schedule.snake.data.mydao.Datasource;
import core.schedule.snake.schedule.core.DsfaTaskHelper;
import core.schedule.snake.schedule.core.JDKTimmer;
import core.schedule.snake.schedule.core.QuartzImpl;
import core.schedule.snake.schedule.core.SchedulerInterface;
import core.schedule.snake.schedule.core.TaskInfo;
import core.tool.common.SystemInfo;
import core.tool.log.log4j.EasyLogger;

public class Main {

	public static void main(String[] args) throws Exception {
		initDatabase();
		initSys();
		TaskInfo taskInfo=DsfaTaskHelper.getTaskInfo();
		EasyLogger.debug("定时器配置信息", taskInfo.toString());
		SchedulerInterface schedulerInterface=null;
		if(TaskInfo.IMPL_TYPE_JDK.equals(taskInfo.getImplType())) {
			schedulerInterface=new JDKTimmer();
		}
		else {
			schedulerInterface=new QuartzImpl();
		}
		schedulerInterface.execute(taskInfo);
	}
	
	
	
	private static void initDatabase() {
		BasicDataSource basicDataSource=(BasicDataSource) SystemInfo.getBean("dataSource");
		Datasource dataBase=new Datasource();
		dataBase.setDriverClassName(basicDataSource.getDriverClassName());
		dataBase.setPassword(basicDataSource.getPassword());
		dataBase.setUrl(basicDataSource.getUrl());
		dataBase.setUsername(basicDataSource.getUsername());
		BaseDAO baseDAO=new BaseDAO();
		baseDAO.setDatasource(dataBase);
	}
	
	
	private static void initSys() {
		EasyLogger.init(SystemInfo.ROOT_PATH);	
	}
	
	
	
}
